package fuzion24.device.vulnerability.test.ui;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;

import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog;
import com.github.paolorotolo.appintro.AppIntro;
import com.github.paolorotolo.appintro.AppIntroFragment;
import com.nowsecure.android.vts.R;

import fuzion24.device.vulnerability.util.SharedPreferencesUtils;

public class AppIntroActivity extends AppIntro {

    @Override
    public void init(Bundle savedInstanceState) {
        addSlide(AppIntroFragment.newInstance(getString(R.string.appintro_security), getString(R.string.appintro_security_description), R.drawable.ic_security, Color.parseColor("#33394F")));
        addSlide(AppIntroFragment.newInstance(getString(R.string.appintro_issues), getString(R.string.appintro_issues_description), R.drawable.ic_bug,  Color.parseColor("#33394F")));
        addSlide(AppIntroFragment.newInstance(getString(R.string.appintro_antivirus), getString(R.string.appintro_antivirus_description), R.drawable.ic_action_lock_open, Color.parseColor("#33394F")));
        addSlide(AppIntroFragment.newInstance(getString(R.string.appintro_sharing), getString(R.string.appintro_sharing_description), R.drawable.ic_file_cloud_upload, Color.parseColor("#33394F")));

        showSkipButton(false);
        showDoneButton(true);
    }

    @Override
    public void onSkipPressed() {
    }

    @Override
    public void onDonePressed() {
        new MaterialDialog.Builder(this)
            .title(R.string.dialog_automatic_sharing_title)
            .content(R.string.dialog_automatic_sharing_description)
            .positiveText(R.string.global_sharing)
            .negativeText(R.string.global_notsharing)
            .onPositive(new MaterialDialog.SingleButtonCallback() {
                @Override
                public void onClick(MaterialDialog materialDialog, DialogAction dialogAction) {
                    SharedPreferencesUtils.setIsAutomaticSharingEnable(AppIntroActivity.this, true);
                }
            })
            .onNegative(new MaterialDialog.SingleButtonCallback() {
                @Override
                public void onClick(MaterialDialog materialDialog, DialogAction dialogAction) {
                    SharedPreferencesUtils.setIsAutomaticSharingEnable(AppIntroActivity.this, false);
                }
            })
            .onAny(new MaterialDialog.SingleButtonCallback() {
                @Override
                public void onClick(MaterialDialog materialDialog, DialogAction dialogAction) {
                    SharedPreferencesUtils.disableFirstRun(AppIntroActivity.this);

                    Intent mainIntent = new Intent(AppIntroActivity.this, MainActivity.class);

                    AppIntroActivity.this.startActivity(mainIntent);
                    AppIntroActivity.this.finish();
                }
            })
            .show();
    }

    @Override
    public void onSlideChanged() {
    }

    @Override
    public void onNextPressed() {
    }

}
